package com.wnxy.carl.carlorderassembly.controller;


import com.wnxy.carl.api.ShoppingApi;
import com.wnxy.carl.carlorderassembly.service.IShoppingCartService;
import com.wnxy.carl.dto.PageDTO;
import com.wnxy.carl.dto.ShoppingDTO;
import com.wnxy.carl.param.IncreaseShopingParam;
import com.wnxy.carl.param.PageParam;
import com.wnxy.carl.response.EPage;
import com.wnxy.carl.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartController implements ShoppingApi {

    @Resource
    private IShoppingCartService shoppingCartService;
    /**
     * 查看用户购物车 PageDTO<ShoppingDTO>
     * @param pageParam
     * @return
     */
    @Override
    public Result<? extends EPage<ShoppingDTO>> seeShoppingCart(PageParam<Integer> pageParam) {
        log.info("查看用户购物车功能：参数={}",pageParam);
        PageDTO<ShoppingDTO> shoppingDTOPageDTO = shoppingCartService.seeShoppingCart(pageParam);
        return Result.success(shoppingDTOPageDTO);
    }

    /**
     * 修改购物车信息 ShoppingDTO
     * @param shoppingCartId
     * @param number
     * @return
     */
    @Override
    public Result<ShoppingDTO> amendShoppingCart(Integer shoppingCartId, Integer number) {
        log.info("修改购物车信息功能：参数={},{}",shoppingCartId,number);
        ShoppingDTO shoppingDTO = shoppingCartService.amendShoppingCart(shoppingCartId, number);
        return Result.success(ShoppingDTO.class,"修改成功",shoppingDTO);
    }

    /**
     * 删除购物商品 Boolean
     * @param shoppingCartId
     * @return
     */
    @Override
    public Result cancelShoping(Integer shoppingCartId) {
        log.info("删除购物商品功能：参数={}",shoppingCartId);
        shoppingCartService.cancelShoping(shoppingCartId);
        return Result.success("删除成功");
    }

    /**
     * 添加购物车商品 ShoppingDTO
     * @param shopingParam
     * @return
     */
    @Override
    public Result<ShoppingDTO> increaseShoping(IncreaseShopingParam shopingParam) {
        log.info("添加购物车商品功能：参数={}",shopingParam);
        ShoppingDTO shoppingDTO = shoppingCartService.increaseShoping(shopingParam);
        return Result.success(ShoppingDTO.class,"添加成功",shoppingDTO);
    }
}

